// pages/user_integral_account/user_integral_account.js
var app = getApp();
var req = require("../../utils/req.js");
var url = require("../../utils/url.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current_page: 0,
    integralDetail: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getIntegralAccountList();
  },
  /**
   * 得到金币明细的数据
   */
  getIntegralAccountList: function () {
    var that = this;
    var data = {
      page: that.data.current_page
    }
    req.userRequest("请稍等", 'POST',url.user['userFractionDetail'], data, function back(res) {
      var data = res.data;

      if (that.data.integralDetail.length == 0 && data.length == 0) {
        wx.showToast({
          icon: 'none',
          title: '暂无记录',
        })
      }

      //判断数据是否为null
      if (data.length!=0) {
        //合并数组
        that.data.integralDetail.push.apply(that.data.integralDetail, data);
        that.setData({
          integralDetail: that.data.integralDetail
        })
        console.log(that.data.integralDetail);
      } else {
        wx.showToast({
          icon: 'none',
          title: '已经到底了！',
        })
      }
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log('fresh');
    var that = this;
    this.getProList(() => {
      that.data.isLoadedAll = false;
      wx.stopPullDownRefresh();
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.isLoadedAll) {
      this.data.current_page++;
      this.getIntegralAccountList();
    }
  },
})